package kr.hkit.team.score.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import kr.hkit.myframework.db.DbUtil;
import kr.hkit.team.score.dto.Score;

public class ScoreDAO {

	private Connection connection;

	public ScoreDAO(Connection connection) {
		this.connection = connection;
	}
	
	
	public void insertItems(Score item) throws SQLException { // 입력 - score

		String sql = "insert into score values (?,?,?,?)";
		PreparedStatement pstmt = connection.prepareStatement(sql);

		pstmt.setInt(1, item.getStdNum());
		pstmt.setInt(2, item.getKor());
		pstmt.setInt(3, item.getEng());
		pstmt.setInt(4, item.getMath());

		pstmt.executeUpdate();
		DbUtil.close(pstmt);

	}
	
	
	public Score searchItems(Score item) throws SQLException { //포커스 아웃용

		Score sc = null; 
		
		String sql = "select stdName from student where stdNum=?";
		PreparedStatement pstmt = connection.prepareStatement(sql);
		pstmt.setInt(1, item.getStdNum());

		ResultSet rs = pstmt.executeQuery();

		if (rs.next()) {
			sc = new Score();
			sc.setStdName(rs.getString(1));
		}

		DbUtil.close(rs);
		DbUtil.close(pstmt);

		return sc;
	}
	
}
